"""
-----------------------------
   File Name:kdtxapi
   Author:cwei
   date: 2023/7/30-15:45
-----------------------------
"""
import requests


class KDTXAPI:
    # 封装一个生成验证码接口
    @classmethod
    def get_code_api(cls):
        url = "http://kdtx-test.itheima.net/api/captchaImage"
        resp = requests.get(url)
        return resp
        pass

    # 封装登录的接口
    @classmethod
    def login_api(cls, body):
        url = "http://kdtx-test.itheima.net/api/login"
        header = {"content-type": "application/json"}
        resp = requests.post(url=url, headers=header, json=body)
        return resp
        pass

    # 合同上传接口
    @classmethod
    def upload_contract(cls, token, f):
        upload_url = "http://kdtx-test.itheima.net/api/common/upload"
        upload_header = { "Authorization": token}
        # multipart/form-data 不用写在 header里Content-Type,在下面格式中体现
        upload_res = requests.post(url=upload_url, headers=upload_header, files={"file": f})
        return upload_res
        pass

    # 新增合同接口
    @classmethod
    def add_contract(cls, token, add_body):
        add_url = "http://kdtx-test.itheima.net/api/contract"
        add_header = {"Content-Type": "application/json", "Authorization": token}

        add_res = requests.post(url=add_url, headers=add_header, json=add_body)
        return add_res

        pass

    # 查询合同列表接口
    @classmethod
    def query_contract(cls, token):
        query_url = "http://kdtx-test.itheima.net/api/contract/list"
        query_header = {"Authorization": token}

        query_res = requests.get(url=query_url, headers=query_header)
        return query_res
        pass

    # 删除合同接口
    @classmethod
    def del_contract(cls, token, del_body):
        del_url = "http://kdtx-test.itheima.net/api/contract/remove"
        del_header = {"Content-Type": "application/x-www-form-urlencoded", "Authorization": token}

        del_res = requests.post(url=del_url, headers=del_header, data=del_body)
        return del_res
        pass

    pass
